import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZonelessChangeDetection } from '@angular/core';
import { HttpHandlerFn, HttpRequest, provideHttpClient, withInterceptors } from '@angular/common/http';
import { provideRouter } from '@angular/router';
import { routes } from './app.routes';

function loginInterceptor(request: HttpRequest<unknown>, next: HttpHandlerFn) {
  //从Cookie获取jwt令牌
  const jwtStr = localStorage.getItem("Authorization") ?? "";
  const req = request.clone({
    headers:request.headers.set("Authorization",jwtStr)
  });
  return next(req);
}

export const appConfig: ApplicationConfig = {
  providers: [
    provideBrowserGlobalErrorListeners(),
    provideZonelessChangeDetection(),
    provideRouter(routes),
    provideHttpClient(withInterceptors([loginInterceptor])),
  ]
};
